package work.xiaohong.pay.AliPay.config;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @author xiaohong
 * @version 1.0
 * @date 2021/9/17 0017 22:56
 */
@Configuration
public class AlipayConfig {
    //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2021000116675453";

    // 商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDPWX3OwX/GknsutHAD27SHdjjvbtQI67n0FQWO/f3Fhmn5kUZZerYT4ibGQTgbqoTwfDMfdY5a/TG0vfsjbWEkD7kJxBlst32V/hmsCq22vw87mWOx7TVEY77fRL50MHowWiv6ZKeOKZIl7WjWKUqMlT3VJHsdjs7skafqYCDdlrtHRr5SMpevUNWu1J6ViB+wPhRqLOhh5nRJ63zLF2DRXb9XYGYFGMyJGtFMaIZ0B1V9g+urbh4RNNfV2zisBUMP8H4Z9ekr9cCmtGTfcWGfxRUKvcgPsu0qKUke+D5NDUewn5LlErDxsB1RXGxxF8NNjgr1Y8jqWWeokXTJS6DAgMBAAECggEAWkYplV4sScWzg/sdvJbhC/cr8bvY1M82yI4syP6HGpdBHpTugwHwAMr0lHspN5fntZ96G6+TY/w2a21CzJzNd1ohaJ7WUJ4wv/rTCw+y0gTf7Kmvgf8tDEL/r03hd6V5PLmNYTOxftRIzTZN4wZe1h+5AkhR9+174RxIKBtYIxSRp5nV70x8Pv2O1PK00QNKWbyATF92BwsFUyp0R0VJFMfORcEEPBw8JWfQ4Z6OlrOD5EGIOJ3uE8MdX252NkT752wQdgma6zm1pW60Na+zipslWwlTvTPKlSebi47P61LlKsIu/tCWll0PVJkbDmcI0ahNbH/LbbLDBJsG2RRTQQKBgQDFiejPfMWpEYnRkGp/NO6p040zEfn3PWdjRE/WhNw6zQmyTlQwPBnvEXBwxpB52W2im6r003PqCIlqEwgV54875KgeHHTzBXE7fYSCVpzHKLKSSY1xP+i53G5GJYJqkSII/Jsc4KeIbdTSH9Jv6oDXkU7Wk//AlhFO4zeGfsb61wKBgQCqFH/Ex2nCg53DiPnckC6Qzt8fSWfxGUvNKXz75tSzCEaQOb1BkNtJdZcA8Abf5YMVa1meAGX429l60dp1+6fDmHyntXUi7NA08Wnv/am+S+ghPV5WF4loP27uFWdWurz82o8tzZoXNJ+3FMEDR8Y8nGFSTR45JZ1Dh67T7n7ANQKBgGcViMB+REfuNxV9X5XycXl+RHkaMG+tQ36x71frDWJCDYVXCugA9Sek2iB//nUX2fa5dYU9s4e13L/WHqoPpNeEg5bzErSfam+5GKVLvZTQ0B828vDegPw84+8HM/+YrUIzUF7JfaPcbOsaYB63KXVVBudDZHuD1JRuTlOJZR0RAoGAOOOMbSSKYo6lmX7anIT5nmQjy5JBGyrr6N7kuFlYcd3lxF4byK+MOcEEVkLy+bcKJoL2wdu+QARBdUx2NxqK3ejGYU5XtOvjJKJPXf/J5CX9qgid4kwTIPR+xVIRc7gYeLceRyLLVNG8Tn+5o8BBNYrVHrM+1byYIrtipe7TJLUCgYEAuIQJvKPmrzPVvlxKbzpKazkN98tKfqc+/5ZAeNB3e8/do9621vyc2x6kkdkU09XiTamhysoCL9rah3I8HzSVKOO/GBQ2ZjjcGkVW5hAfLZ4MoOvYQ7KQtgt05rX5vpc2G206rKvE94AYp4v+CfOSusvMtk1pUp017EETyMJkeYU=";

    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnTxmI9DOWQaGf0DmWOLxKqeMbtHzhVOLRcTGkrbj5u3r/+t98nkBGAf0xpS0eziCkE12s1NuXBEiLC4RdTeP/VfT9rbu2sktGU1YMPNYQiJNRkA+q+gOEULlwbub5SP/7g+Oqq68UgTU6sck0+AkExFVCPL7WykwkT9CRs2/ZBtknta857T2BvvLuzvl/W0pdKhI7VynsZeGh4PeiK5IxeNZcF77IQBuCCjJWCkSLPojBX8kzf78hCcBKYN9dF3XEhIgRyjKSZlhxdzuGwo3bsS3OtSjD8H97AyBU2JFo1vp8V6nwmTpM4aobtg7D4yUzN9ZVclpyJgDRIGSNkPdhwIDAQAB";

    // 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
//	public static String notify_url = "http://119.29.67.157:9007/AliPay/callback/notify_url.jsp";
    public static String notify_url = "http://pay.xiaohong.work/pay/AliPay/notify";

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://pay.xiaohong.work/pay/AliPay/return";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

    // 支付宝网关
    public static String log_path = "C:\\";


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑


    @Bean
    public AlipayClient alipayClient(){
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
        return alipayClient;
    }

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
//    public static void logResult(String sWord) {
//        FileWriter writer = null;
//        try {
//            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
//            writer.write(sWord);
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (writer != null) {
//                try {
//                    writer.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }


}
